<?php
namespace app\index\controller;
use app\index\model\Member as Members;
use app\index\model\Start;
use think\Config;
use think\Request;
use think\Validate;
use think\db;
class Member extends Base
{
    public function memberList(){
        $where['status']     = array('eq', 1);
        $where['head_pic']   = array('neq','');
        $whereOr['nickname'] = array('like','%烧%');
        $whereOr['age']       = 18;
        $members = Members::where($where) ->whereOr($whereOr) ->field('id, nickname, head_pic, account, create_time') ->select();
        $this ->assign('members',$members);
        return $this ->fetch();
    }

    public function addMember(){
        $data['username'] = 'test1';
        $data['password'] = md5('1234567890');
        $data['email']    = '13724654186@qq.com';
        $res = Start::create($data);
        if(empty($res)){
            var_dump('装逼失败');
        }else{
            var_dump($res ->id);
        }
    }

    public function saveMember(){
        $where['id']       = 1;
        $where['status']  = array('neq',9);
        $data['password'] = md5('123456');
        $data['email']    = '836411277@qq.com';
        $res = Start::update($data, $where);
        if(empty($res)){
            var_dump('装逼失败');
        }else{
            var_dump($res ->toArray());
        }
    }

    public function deleteMember(){
        $member = Start::get(2);
        $res = $member ->delete();
        if(empty($res)){
            var_dump('装逼失败');
        }else{
            var_dump($res);
        }
    }


    public function hasManyCreate(){
        $member = Members::find(2);
        $data['g_id'] = '100';
        $data['num'] = '1';
        $data['merchant_id'] = '24';
        $data['haven_id'] = '11';
        $res = $member ->carts()->save($data);
        var_dump($res ->toArray());
    }

    public function hasManyUpdate(){
        $member = Members::field('id, nickname, account, create_time') -> find(2);
        var_dump($member ->carts ->toArray());
    }
}
